import 'dart:async';

class WebRtcDataChannelBean{
  String type = "";//text  file
  String fileName = "";
  String connect = "";
  WebRtcDataChannelBean();
  WebRtcDataChannelBean.fromJson(Map<String, dynamic>? json) {
    this.type = json!['type'].toString();
    this.fileName = json['fileName'].toString();
    this.connect = json['connect'].toString();
  }

  Map toJson() {
    Map map = Map();
    map["type"] = type;
    map["fileName"] = fileName;
    map["connect"] = connect;
    return map;
  }
}



class WebRtcDataChannelReceiveFile{
  String filePath = "";
  String name = "";
  int fileAllLen = 0;
  int curfileLen = 0;
  List<int> datas=[];
  final controller = StreamController<int>();
  void start(String filePath,int fileAllLen){
   this.filePath = filePath;
   this.fileAllLen = fileAllLen;
  }

  Future<void> appendData(List<int> data) async {
    data.forEach((element) {
      controller.add(element);
    });
    // controller.add(event)
    curfileLen += data.length;
    print("appendData:${(curfileLen)*1.0/fileAllLen*1.0}");

  }
  void saveFile(){
    controller.close();
    // download(controller.stream, name);
  }

}